package xhq.java.test.utilities.types;

/**
 * @author hq_xu
 * @since 2021/2/2 13:40
 */
public class NumberUtils {
    private NumberUtils() {
    }

    public static int toInt(String str, int defaultValue) {
        if (str == null) {
            return defaultValue;
        } else {
            try {
                return Integer.parseInt(str);
            } catch (NumberFormatException ex) {
                return defaultValue;
            }
        }
    }

    public static Long toLong(String str, Long defaultValue) {
        if (str == null) {
            return defaultValue;
        } else {
            try {
                return Long.valueOf(str);
            } catch (NumberFormatException ignored) {
                return defaultValue;
            }
        }
    }

    public static Long toLong(String str) {
        return StringUtils.isNotBlank(str) ? Long.valueOf(str) : null;
    }
}
